home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
pcl4w13.zip
/
LOGIN.C
< prev
next >
Wrap
Text File
|
1996-07-14
|
14KB
|
409 lines
/*
** --- login.c ---
**
** EXAMPLE CODE: Very login terminal emulator, capbale of logging onto a BBS.
**
** This example program (not the PCL4W library) is donated to
** the Public Domain by MarshallSoft Computing, Inc. It is
** provided as an example of the use of the PCL4W.
**
*/
#define USECOMM
#include "windows.h"
#include "stdio.h"
#include "pcl4w.h"
#include "sioerror.h"
#include "ascii.h"
#include "login.h"
#include "message.h"
#include "line.h"
#include "paint.h"
#include "about.h"
#include "mio.h"
#define ONE_SEC 1000L
#define ULONG unsigned long
#define Handshake_1 11
#define Handshake_2 12
#define Handshake_3 13
#define Dial_1 21
#define Dial_2 22
#define Dial_3 23
/* public globals */
HWND hMainWnd; /* main window handle */
int OnLineFlag = FALSE; /* TRUE: online */
int FatalFlag = FALSE; /* TRUE: fatal error */
/* private globals */
static HMENU hMenu;
static HANDLE hInstance;
static int ThePort = COM1;
static int TheBaud = Baud19200;
static int WinWidth = 8 * NCOLS;
static int WinHeight = 12 * NROWS + 48;
static long BaudRateList[10]
= {300L,600L,1200L,2400L,4800L,9600L,19200L,38400L,57600L,115200L};
static int mioState = 0;
static char Temp[1024];
/* miscellaneous functions */
void ErrorCheck(int);
int PutGet(char *,char *,ULONG);
int PASCAL WinMain(HANDLE hInst,HANDLE hPrevInstance,
LPSTR lpCmdLine,int nCmdShow)
{WNDCLASS wc;
MSG msg;
BOOL Result;
if(!hPrevInstance)
{/* register main window class */
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, "LoginIcon");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "LoginMenu";
wc.lpszClassName = "LoginWClass";
Result = RegisterClass(&wc);
if(!Result) return FALSE;
}
/* create main window */
hInstance = hInst;
hMainWnd = CreateWindow(
"LoginWClass", "LOGIN", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
WinWidth, WinHeight,
NULL, NULL,
hInstance, NULL);
ShowWindow(hMainWnd, nCmdShow);
UpdateWindow(hMainWnd);
hMenu = GetMenu(hMainWnd);
/* window control loop */
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
} /* end WinMain */
long FAR PASCAL MainWndProc(HWND hWindow,UINT message,WPARAM wParam,LPARAM lParam)
{
UINT idTimer;
HDC hDC;
PAINTSTRUCT ps;
int i, rc;
int TheChar;
int Count;
int Code;
static FARPROC lpProcAbout;
hMainWnd = hWindow;
switch (message)
{
case WM_COMMAND:
switch(wParam)
{case MSG_ABOUT:
DialogBox(hInstance,"AboutBox",hMainWnd,lpProcAbout);
break;
case MSG_BREAK:
mioBreak(ThePort);
EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_GRAYED);
mioState = 0;
break;
case MSG_HANDSHAKE:
if(!OnLineFlag) DisplayLine("Must be online!");
else
{mioState = Handshake_1;
EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_ENABLED);
}
break;
case MSG_DIAL:
if(!OnLineFlag) DisplayLine("Must be online!");
else
{mioState = Dial_1;
EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_ENABLED);
}
break;
case MSG_DEBUG:
break;
case MSG_ONLINE:
if(OnLineFlag) break;
else
{/* try to go on-line */
if(GoOnLine(ThePort,TheBaud,Size1024,Size1024))
{/* we're online */
OnLineFlag = TRUE;
sprintf(Temp,"LOGIN: COM%d online at %ld baud",
1+ThePort,BaudRateList[TheBaud]);
SetWindowText(hMainWnd,Temp);
CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_CHECKED);
for(i=MSG_COM1;i<=MSG_COM4;i++)
EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_GRAYED);
for(i=MSG_300;i<=MSG_115200;i++)
EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_GRAYED);
}
}
break;
case MSG_OFFLINE:
if(!OnLineFlag) break;
GoOffLine(ThePort);
OnLineFlag = FALSE;
SetWindowText(hMainWnd,"LOGIN: Offline");
CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_CHECKED);
for(i=MSG_COM1;i<=MSG_COM4;i++)
EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_ENABLED);
for(i=MSG_300;i<=MSG_115200;i++)
EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_ENABLED);
break;
case MSG_EXIT:
DestroyWindow(hMainWnd);
break;
case MSG_COM1:
CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
ThePort = COM1;
CheckMenuItem(hMenu,MSG_COM1,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_COM2:
CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
ThePort = COM2;
CheckMenuItem(hMenu,MSG_COM2,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_COM3:
CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
ThePort = COM3;
CheckMenuItem(hMenu,MSG_COM3,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_COM4:
CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
ThePort = COM4;
CheckMenuItem(hMenu,MSG_COM4,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_300:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud300;
CheckMenuItem(hMenu,MSG_300,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_1200:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud1200;
CheckMenuItem(hMenu,MSG_1200,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_2400:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud2400;
CheckMenuItem(hMenu,MSG_2400,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_4800:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud4800;
CheckMenuItem(hMenu,MSG_4800,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_9600:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud9600;
CheckMenuItem(hMenu,MSG_9600,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_19200:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud19200;
CheckMenuItem(hMenu,MSG_19200,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_38400:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
TheBaud = Baud38400;
CheckMenuItem(hMenu,MSG_38400,MF_BYCOMMAND | MF_CHECKED);
break;
case MSG_57600:
CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);